/***************************************************
> Copyright (C) 2023 ==KINGYI== All rights reserved.
> File Name: queue.c
> Author:li
> Mail:joseph2009@163.com 
> Created Time: 2023年09月14日 星期四 17时43分38秒
***************************************************/

#include <stdio.h>
#include "queue.h"


struct queue* create_queue(void)
{
	QUE* que = NULL;
	que = malloc(sizeof(QUE));
	if(que == NULL)
	{
		perror("create_queue");
		return NULL;
	}
	memset(&que->info,0,sizeof(struct message));
	que->next = NULL;

	return que;
}
void push(struct queue* que,struct message info)
{
	QUE* tail = que;

	while(tail->next != NULL)
	{
		tail = tail->next;
	}

	tail->next = malloc(sizeof(QUE));
	tail = tail->next;
	tail->info = info;
	tail->next = NULL;
}
struct message front(struct queue* que)
{
	QUE* head = que->next;
	return head->info;
}
void pop(struct queue* que)
{
	QUE* head = que->next;
	que->next = head->next;
	head->next = NULL;
	free(head);
}
int isempty(struct queue* que)
{
	QUE* head = que;
	if(head->next == NULL)
	{
		return 0;//null
	}
	else
	{
		return 1;//not null
	}
}
int size(struct queue* que)
{
	QUE* tail = que;
	int count = 0;

	while(tail->next != NULL)
	{
		tail = tail->next;
		count++;
	}
	return count;
}

